package com.jsgt.greekfire.ui.mine.assetsmanage

import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.fhx.core.base.BaseActivity
import com.jsgt.greekfire.R
import com.jsgt.greekfire.bean.AssetsBean
import com.jsgt.greekfire.factory.CoinViewModelFactory
import com.jsgt.greekfire.factory.UserViewModelFactory
import com.jsgt.greekfire.ui.mine.assetsmanage.adapter.AssetsManageAdapter
import com.jsgt.greekfire.viewmodel.CoinViewModel
import com.jsgt.greekfire.viewmodel.UserViewModel
import kotlinx.android.synthetic.main.recyclerview.*

/**
 * 资产管理
 * author fhx
 * create time 2020/4/24 12:40
 **/
class AssetsManageActivity : BaseActivity() {
    private val userViewModel: UserViewModel by lazy {
        ViewModelProvider(
            this,
            UserViewModelFactory()
        ).get(UserViewModel::class.java)
    }
    private val coinViewModel: CoinViewModel by lazy {
        ViewModelProvider(
            this,
            CoinViewModelFactory()
        ).get(CoinViewModel::class.java)
    }

    override fun getLayoutId(): Int = R.layout.recyclerview

    override fun main() {
        showTitleView()
        title = getString(R.string.assets_manage)
        val manageAdapter =
            AssetsManageAdapter()
        manageAdapter.setOnCheckedListener(object : AssetsManageAdapter.OnCheckedListener {
            override fun onChecked(isChecked: Boolean, bean: AssetsBean) {
                if (isChecked) {
                    coinViewModel.userAssetUpdate(bean.assetGuid!!, "1")
                } else {
                    coinViewModel.userAssetUpdate(bean.assetGuid!!, "0")
                }
            }
        })
        recyclerview.layoutManager =
            LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
        recyclerview.adapter = manageAdapter
        userViewModel.userAssetManageList()
        userViewModel.assetsManageListLiveData.observe(this, Observer {
            manageAdapter.addData(it)
        })
        coinViewModel.assetUpdateLiveData.observe(this, Observer {

        })
    }

    /**
     * 目前只有一种类型货币，下个版本使用
     */
    /*private fun initIndicator() {
        val commonNavigator = CommonNavigator(this)
        commonNavigator.isAdjustMode = false
        commonNavigator.adapter = object : CommonNavigatorAdapter() {
            override fun getCount(): Int {
                return 4
            }

            override fun getTitleView(context: Context, index: Int): IPagerTitleView {
                val colorTransitionPagerTitleView = ColorTransitionPagerTitleView(context)
                colorTransitionPagerTitleView.normalColor =
                    ContextCompat.getColor(context, R.color.gray_C7CBD2)
                colorTransitionPagerTitleView.selectedColor =
                    ContextCompat.getColor(context, R.color.yellow_F0CF51)
                colorTransitionPagerTitleView.text = "主链"
                colorTransitionPagerTitleView.typeface = Typeface.DEFAULT_BOLD
                colorTransitionPagerTitleView.textSize = 16f
                colorTransitionPagerTitleView.setOnClickListener { viewpager.currentItem = index }
                return colorTransitionPagerTitleView
            }

            override fun getIndicator(context: Context): IPagerIndicator {
                val linePagerIndicator = LinePagerIndicator(context)
                linePagerIndicator.mode = LinePagerIndicator.MODE_EXACTLY
                linePagerIndicator.setColors(ContextCompat.getColor(context, R.color.yellow_F0CF51))
                linePagerIndicator.lineWidth = ScreenUtil.dip2px(context, 30f)
                linePagerIndicator.lineHeight = ScreenUtil.dip2px(context, 1f)
                return linePagerIndicator
            }
        }
        indicator.navigator = commonNavigator
        ViewPagerHelper.bind(indicator, viewpager)

        val fragments = arrayListOf<Fragment>()
        fragments.add(AssetsManageListFragment())
        fragments.add(AssetsManageListFragment())
        fragments.add(AssetsManageListFragment())
        fragments.add(AssetsManageListFragment())
        viewpager.adapter = FragmentAdapter(supportFragmentManager, fragments)
        viewpager.offscreenPageLimit = 3
    }*/
}